var PATH_PREFIX = "";
function setPathPrefix(path){
	PATH_PREFIX =  path;
}
var INVESTMENT_RESEARCH_ADD = function(){
	this.init();
};
/**
 * 初始化方法
 */
INVESTMENT_RESEARCH_ADD.prototype.init = function(){
	var self = this;
	self.expand();
	// 初始化文本域，绑定kindeditor控件
	WASP_WIDGET.triggerKindEditor("researchContent",true);
	
	$("#investmentResearchAddForm").validate({
		focusCleanup : true
	});
	// textarea绑定事件使其高度自适应
    $.each($("textarea"), function(i, n){
        autoTextarea($(n)[0]);
    });
}

/**
 * 拓展方法
 */
INVESTMENT_RESEARCH_ADD.prototype.expand = function(){
	var self = this;
	
	self.validate = function() {
		$("#researchTitle").rules("remove");
		$("#researchAbstract").rules("remove");
		$("#researchContent").rules("remove");
		
		$("#researchTitle").rules("add", {
			required : true, maxlength4Byte: 100 , messages: {required: "请填写标题", maxlength4Byte:"标题不能大于100个字符"}
		});
		$("#researchAbstract").rules("add", {
			required : true, maxlength4Byte: 2000 , messages: {required: "请填写摘要", maxlength4Byte:"标题不能大于2000个字符"}
		});
		$("#researchContent").rules("add", {
			required : true, messages: {required: "请填写正文"}
		});
	};
	
	self.submitForm = function() {
		SubmitAndPreventSecond("investmentResearchAddForm",function() {
			self.validate();
			
			if(!$("form[name='investmentResearchAddForm']").valid()) {
				toastr.warning('', '请完善信息');
				return false;
			}
			
			$('#investmentResearchAddForm').attr('action', PATH_PREFIX + "saveInvestmentResearch.do");
			
			return true;
		}, true);
	};
}
